//
//  PracticesViewController.m
//  Tableview01
//
//  Created by 大宝 刘 on 11-11-11.
//  Copyright (c) 2011年 北京帷幄昊合数字娱乐科技有限公司. All rights reserved.
//

#import "PracticesViewController.h"

@implementation PracticesViewController

@synthesize listData = _listData;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    NSArray *array = [[NSArray alloc]initWithObjects:@"人之初，性本善。性相近，习相远。", 
                      @"苟不教，性乃迁。教之道，贵以专。", @"昔孟母，择邻处。子不学，断机杼。", 
                      @"窦燕山，有义方。教五子，名俱扬。", @"子不学，非所宜。幼不学，老何为。", 
                      @"为人子，方少时。亲师友，习礼仪。", @"香九龄，能温席。孝于亲，所当执。", 
                      @"融四岁，能让梨。弟于长，宜先知。", @"首孝悌，次见闻。知某数，识某文。", 
                      @"一而十，十而百。百而千，千而万。", nil];
    
    self.listData = array;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

// 添加行数
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSLog(@"listData count is %d", [self.listData count]);
    return [self.listData count];
}

// 设置每行内容
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if(cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    NSUInteger row = [indexPath row];
    NSLog(@"row: %d", row);
    
    NSString *cellLabelText = [[NSString alloc]initWithFormat:@"%@ %d", [_listData objectAtIndex:row], row + 1];
    
    cell.textLabel.text = cellLabelText;
    
    // 修改单元格文字颜色及大小
    UILabel *label = cell.textLabel;
    label.font = [UIFont boldSystemFontOfSize:14];
    label.textColor =[UIColor brownColor];
    label.textAlignment = UITextAlignmentCenter;
    
    UIImage *cellImage = [UIImage imageNamed:@"title.png"];
    cell.imageView.image = cellImage;
    
    
    NSLog(@"the first row content is: %@", [self.listData objectAtIndex:row]);
    
    return cell;
}

@end
